package com.ruoyi.common.utils;


import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class WindUtil {
    public static final List<Map> list = new ArrayList();
    static {
        Map map = new HashMap();map.put("min",0.0);map.put("max",0.3);map.put("key",3);list.add(map);
        map = new HashMap();map.put("min",0.3);map.put("max",1.5);map.put("key",12);list.add(map);
        map = new HashMap();map.put("min",1.5);map.put("max",3.3);map.put("key",18);list.add(map);
        map = new HashMap();map.put("min",3.3);map.put("max",5.4);map.put("key",21);list.add(map);
        map = new HashMap();map.put("min",5.4);map.put("max",7.9);map.put("key",25);list.add(map);
        map = new HashMap();map.put("min",7.9);map.put("max",10.7);map.put("key",28);list.add(map);
        map = new HashMap();map.put("min",10.7);map.put("max",13.8);map.put("key",31);list.add(map);
        map = new HashMap();map.put("min",13.8);map.put("max",17.1);map.put("key",33);list.add(map);
        map = new HashMap();map.put("min",17.1);map.put("max",20.7);map.put("key",36);list.add(map);
        map = new HashMap();map.put("min",20.7);map.put("max",24.4);map.put("key",37);list.add(map);
        map = new HashMap();map.put("min",24.4);map.put("max",28.4);map.put("key",40);list.add(map);
        map = new HashMap();map.put("min",28.4);map.put("max",32.6);map.put("key",42);list.add(map);
    }

    public static final List<Map> ultravioletList = new ArrayList();
    static {
        Map map = null;
        map = new HashMap();map.put("min",0);map.put("max",3);map.put("key",30);map.put("name","最弱");ultravioletList.add(map);
        map = new HashMap();map.put("min",3);map.put("max",5);map.put("key",20);map.put("name","弱");ultravioletList.add(map);
        map = new HashMap();map.put("min",5);map.put("max",7);map.put("key",20);map.put("name","中等");ultravioletList.add(map);
        map = new HashMap();map.put("min",7);map.put("max",10);map.put("key",20);map.put("name","强");ultravioletList.add(map);
        map = new HashMap();map.put("min",10);map.put("max",100);map.put("key",200);map.put("name","很强");ultravioletList.add(map);

    }
    public static final Map<String,String> mapWind = new HashMap();
    static {
        mapWind.put("N","北");mapWind.put("NNE","东北偏北");mapWind.put("NE","东北");mapWind.put("ENE","东北偏东");mapWind.put("E","东");mapWind.put("ESE","东南偏东");
        mapWind.put("SE","东南");mapWind.put("SSE","东南偏南");mapWind.put("S","南");mapWind.put("SSW","西南偏南");mapWind.put("SW","西南");mapWind.put("WSW","西南偏西");
        mapWind.put("W","西");mapWind.put("WNW","西北偏西");mapWind.put("NW","西北");mapWind.put("NNW","西北偏北");
    }
    //根据风级返回风速
    public static String getWindSpeed(String windLevel) {
        if(StringUtils.isEmpty(windLevel)){
            windLevel = "0";
        }
        Map map1 = list.get(Integer.valueOf(windLevel));
        Integer a =  new Random().nextInt(Integer.valueOf(map1.get("key").toString()));
        return PartUtil.format5(a/10.0+Double.valueOf(map1.get("min").toString()),1 );
    }

    /**
     * 通过正则表达式来提取内容
     * @param html 要解析的html文档内容
     * @return 解析结果，可以多次匹配，每次匹配的结果按文档中出现的先后顺序添加进结果List
     */
    public static List<String> getContext(String html,Pattern p) {
        List<String> resultList = new ArrayList();
        Matcher m = p.matcher(html);//开始编译
        while (m.find()) {
            resultList.add(m.group(0));
        }
        return resultList;
    }
    public static String intiWind(String value){
        if(StringUtils.isEmpty(value)){
            return "";
        }
        Iterator<Map.Entry<String, String>> entries = mapWind.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry<String, String> entry = entries.next();
            if(value.equals(entry.getValue())){
                return entry.getKey();
            }
        }
        return "";
    }

    public static String intiCondition(String value){
        if(StringUtils.isEmpty(value)){
            return "";
        }
        Map<String,String> map = new HashMap<>();
        map.put("0","晴");map.put("1","多云");map.put("2","阴");map.put("3","阵雨");map.put("11","阵雪");
        map.put("18","雾");map.put("20","沙尘暴");map.put("29","浮尘");map.put("45","霾");map.put("4","雷阵雨");
        map.put("5","冰雹");map.put("6","雨夹雪");map.put("7","小雨");map.put("8","中雨");map.put("9","大雨");
        map.put("10","暴雨");map.put("12","小雪");map.put("13","中雪");map.put("14","大雪");map.put("15","暴雪");
        Iterator<Map.Entry<String, String>> entries = map.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry<String, String> entry = entries.next();
            if(value.equals(entry.getValue())){
                return entry.getKey();
            }
        }
        return "";
    }

    //根据名称返回强度
    public static String getUvi(String value) {
        if(StringUtils.isEmpty(value)){
            value = "最弱";
        }
        int sum= 10;
        for(int i=0;i<ultravioletList.size();i++){
            if(value.equals(ultravioletList.get(i).get("name").toString())){
                sum = i;
                break;
            }
        }
        if(sum==10){
            return "1";
        }
        Map map1 = ultravioletList.get(sum);
        Integer a =  new Random().nextInt(Integer.valueOf(map1.get("key").toString()));
        return PartUtil.format5(a/10+Double.valueOf(map1.get("min").toString()),0 );
    }
}
